import http from '../http'
import { prefix } from '.'
import type { MenuItem, RoleItem } from '../types'
/**
 * @description 查询角色列表
 */
export const _queryRoles = (params = {}) =>
  http.get<DataListType<RoleItem>>(`${prefix}/role/list`, {
    params
  })

/**
 * @description 根据角色id查询角色详情
 */
export const _queryRoleDetail = (id: number) =>
  http.get<DataType<RoleItem>>(`${prefix}/role/detail`, { params: { id } })

/**
 * 新增角色
 */
export const _addRole = data => http.post(`${prefix}/role`, data)

/**
 * @description 更新角色
 */
export const _updateRole = data => http.patch(`${prefix}/role/update`, data)

/**
 * @description 删除角色
 * @param id 角色Id
 */
export const _deleteRole = (id: number) => http.delete(`${prefix}/role/${id}`)

/**
 * @description 根据roleId查询menuTree
 * @param params roleId 角色Id
 * @returns menu[] menu list
 */
export const _queryMenuTreeByRoleId = (id: number) =>
  http.get<DataType<MenuItem[]>>(`${prefix}/role/menuTree`, {
    params: { id }
  })

/**
 * @description 更新角色下分配的菜单
 * @param roleId roleId 角色Id
 * @param menuIds menuIds 菜单Id
 */
export const _bindRoleAuthMenu = data =>
  http.post(`${prefix}/role/bindRoleAuthMenu`, data)

/**
 * @description 更新角色下分配的菜单
 * @param {number} data.roleId roleId 角色id
 * @param {number} data.menuId menuId 菜单id
 * @param {string[]} data.operationCodes operationcode 操作编码

 */
export const _bindRoleAuthOperation = data =>
  http.post(`${prefix}/role/bindRoleAuthOperation`, data)

/**
 * @description 更新角色下分配的菜单
 * @param {number} data.roleId roleId 角色id
 * @param {number} data.menuId menuId 菜单id
 * @param {string[]} data.permissions 接口权限集合
 */
export const _bindRoleAuthPermission = data =>
  http.post(`${prefix}/role/bindRoleAuthPermission`, data)

/**
 * @description 查询
 * @param {number} data.roleId roleId 角色id
 */
export const _queryRoleAuth = (roleId: number) =>
  http.get(`${prefix}/role/permission`, { params: { roleId } })
